package com.jimbo.buildRunBat;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import org.apache.commons.lang3.StringUtils;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author 13752
 */
public class MainFrame extends javax.swing.JFrame {

    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox<>();
        jPasswordField1 = new javax.swing.JPasswordField();
        saveBtn = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jarFilePathText = new javax.swing.JTextField();
        jarFilePathBtn = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        configFilePathText = new javax.swing.JTextField();
        configFilePathBtn = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        savePathText = new javax.swing.JTextField();
        savePathBtn = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        saveNameText = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        debugPortCheckBox = new javax.swing.JCheckBox();
        debugPortText = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        monitorPortCheckBox = new javax.swing.JCheckBox();
        monitorPortText = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        serviceDescriptionText = new javax.swing.JTextArea();
        saveNameTitle = new javax.swing.JButton();
        serviceTitle = new javax.swing.JButton();
        debugPortTitle = new javax.swing.JButton();
        monitorPortTitle = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        startMode = new javax.swing.JComboBox<>();
        startModeTitle = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jPasswordField1.setText("jPasswordField1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Spring boot-jar build run bat");

        saveBtn.setText("生成");
        saveBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                saveBtnMouseClicked(evt);
            }
        });
        saveBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveBtnActionPerformed(evt);
            }
        });

        jLabel1.setText("运行文件");

        jarFilePathText.setEnabled(false);

        jarFilePathBtn.setText("...");
        jarFilePathBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jarFilePathBtnMouseClicked(evt);
            }
        });
        jarFilePathBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jarFilePathBtnActionPerformed(evt);
            }
        });

        jLabel2.setText("配置文件");

        configFilePathText.setEnabled(false);

        configFilePathBtn.setText("...");
        configFilePathBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                configFilePathBtnMouseClicked(evt);
            }
        });
        configFilePathBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                configFilePathBtnActionPerformed(evt);
            }
        });

        jLabel3.setText("保存地址");

        savePathText.setEnabled(false);

        savePathBtn.setText("...");
        savePathBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                savePathBtnMouseClicked(evt);
            }
        });
        savePathBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                savePathBtnActionPerformed(evt);
            }
        });

        jLabel4.setText("保存名称");

        jLabel5.setText("调试端口");

        debugPortCheckBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                debugPortCheckBoxItemStateChanged(evt);
            }
        });
        debugPortCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                debugPortCheckBoxActionPerformed(evt);
            }
        });

        debugPortText.setEnabled(false);

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("作者：刘金平 WeChat：liu19951222");
        jLabel6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jLabel7.setText("监控端口");

        monitorPortCheckBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                monitorPortCheckBoxItemStateChanged(evt);
            }
        });
        monitorPortCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                monitorPortCheckBoxActionPerformed(evt);
            }
        });

        monitorPortText.setEnabled(false);

        jLabel8.setText("服务说明");

        serviceDescriptionText.setColumns(20);
        serviceDescriptionText.setRows(5);
        jScrollPane1.setViewportView(serviceDescriptionText);

        saveNameTitle.setText("??");
        saveNameTitle.setToolTipText("生成的服务名称，及保持的文件夹名称");
        saveNameTitle.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        saveNameTitle.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                saveNameTitleMouseClicked(evt);
            }
        });
        saveNameTitle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveNameTitleActionPerformed(evt);
            }
        });

        serviceTitle.setText("??");
        serviceTitle.setToolTipText("生成的服务名称，及保持的文件夹名称");
        serviceTitle.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        serviceTitle.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                serviceTitleMouseClicked(evt);
            }
        });
        serviceTitle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                serviceTitleActionPerformed(evt);
            }
        });

        debugPortTitle.setText("??");
        debugPortTitle.setToolTipText("生成的服务名称，及保持的文件夹名称");
        debugPortTitle.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        debugPortTitle.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                debugPortTitleMouseClicked(evt);
            }
        });
        debugPortTitle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                debugPortTitleActionPerformed(evt);
            }
        });

        monitorPortTitle.setText("??");
        monitorPortTitle.setToolTipText("生成的服务名称，及保持的文件夹名称");
        monitorPortTitle.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        monitorPortTitle.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                monitorPortTitleMouseClicked(evt);
            }
        });
        monitorPortTitle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                monitorPortTitleActionPerformed(evt);
            }
        });

        jLabel9.setText("启动模式");

        startMode.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "开机自启", "手动启动" }));
        startMode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startModeActionPerformed(evt);
            }
        });

        startModeTitle.setText("??");
        startModeTitle.setToolTipText("生成的服务名称，及保持的文件夹名称");
        startModeTitle.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        startModeTitle.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                startModeTitleMouseClicked(evt);
            }
        });
        startModeTitle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startModeTitleActionPerformed(evt);
            }
        });

        jLabel10.setText("JVM相关-------------------------------------------");

        jLabel11.setText("GC日志打印");

        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(saveBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jarFilePathText)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jarFilePathBtn))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(66, 66, 66)
                                .addComponent(savePathText))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(configFilePathText)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(configFilePathBtn, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(savePathBtn, javax.swing.GroupLayout.Alignment.TRAILING)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel7))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(monitorPortCheckBox)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(monitorPortText))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(debugPortCheckBox)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(debugPortText))))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(startMode, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(saveNameText)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(saveNameTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)
                                .addComponent(startModeTitle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(monitorPortTitle, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)
                                .addComponent(debugPortTitle, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(serviceTitle, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jCheckBox1)))
                        .addGap(0, 2, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jarFilePathBtn)
                    .addComponent(jarFilePathText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(1, 1, 1)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(configFilePathBtn)
                    .addComponent(configFilePathText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(1, 1, 1)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(savePathBtn)
                    .addComponent(savePathText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(1, 1, 1)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(saveNameText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(saveNameTitle))
                .addGap(1, 1, 1)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(startMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(startModeTitle))
                    .addComponent(jLabel9))
                .addGap(1, 1, 1)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(serviceTitle))
                .addGap(1, 1, 1)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel5)
                    .addComponent(debugPortCheckBox)
                    .addComponent(debugPortText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(debugPortTitle))
                .addGap(1, 1, 1)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(monitorPortText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(monitorPortCheckBox)
                    .addComponent(jLabel7)
                    .addComponent(monitorPortTitle))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel11)
                    .addComponent(jCheckBox1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 53, Short.MAX_VALUE)
                .addComponent(saveBtn)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBtnActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_saveBtnActionPerformed

    private void jarFilePathBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jarFilePathBtnActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jarFilePathBtnActionPerformed

    private void configFilePathBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configFilePathBtnActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_configFilePathBtnActionPerformed

    private void savePathBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_savePathBtnActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_savePathBtnActionPerformed

    private void debugPortCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_debugPortCheckBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_debugPortCheckBoxActionPerformed

    private void debugPortCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_debugPortCheckBoxItemStateChanged
        // TODO add your handling code here:
        JCheckBox jcb = (JCheckBox) evt.getItem();
        debugPortText.setEnabled(jcb.isSelected());
        debugPortText.setText(null);
    }//GEN-LAST:event_debugPortCheckBoxItemStateChanged

    private void jarFilePathBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jarFilePathBtnMouseClicked
        // TODO add your handling code here:
        File file = selectFile(jarFilePathBtn);
        if (file != null) {
            String fileName = file.getName();
            int index = fileName.lastIndexOf("jar");
            if (index != fileName.length() - 3) {
                showErrorMsg("文件格式不正确,请选择.jar的文件");
                return;
            }
            sourceJarFile = file;
            jarFilePathText.setText(fileName);
        }
    }//GEN-LAST:event_jarFilePathBtnMouseClicked

    private void configFilePathBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_configFilePathBtnMouseClicked
        // TODO add your handling code here:
        File file = selectFile(configFilePathBtn);
        if (file != null) {
            saveConfigFile = file;
            configFilePathText.setText(file.getName());
        }
    }//GEN-LAST:event_configFilePathBtnMouseClicked

    private void savePathBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_savePathBtnMouseClicked
        // TODO add your handling code here:
        File file = selectDirectories(savePathBtn);
        if (file != null) {
            saveSource = file;
            savePathText.setText(file.getAbsolutePath());
        }
    }//GEN-LAST:event_savePathBtnMouseClicked

    private void saveBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveBtnMouseClicked
        // TODO add your handling code here:
        String jarName = jarFilePathText.getText();
        String configName = configFilePathText.getText();
        String savePath = savePathText.getText();
        String saveName1 = saveNameText.getText();
        String debugPort = debugPortText.getText();
        String monitorPort = monitorPortText.getText();
        String desc = serviceDescriptionText.getText();
        String startModeStr = (String) startMode.getSelectedItem();
        startModeStr = startModeStr.equals("开机自启") ? Save.START_MODE_AUTOMATIC : Save.START_MODE_MANUAL;
        Integer debuggerPort = null;
        Integer moitorPort = null;
        if (StringUtils.isBlank(jarName)) {
            showErrorMsg("请先选择运行jar包");
            return;
        }
        if (StringUtils.isBlank(savePath)) {
            showErrorMsg("请选择保存地址");
            return;
        }
        if (StringUtils.isBlank(saveName1)) {
            showErrorMsg("请输入保存名称");
            return;
        }
        if (StringUtils.isNotBlank(debugPort)) {
            try {
                debuggerPort = Integer.valueOf(debugPort);
                if (debuggerPort > 65535 || debuggerPort < 1) {
                    showErrorMsg("端口号错误,只能输入1-66535");
                    return;
                }
            } catch (Exception ex) {
                showErrorMsg("端口号只能输入数字");
                return;
            }
        }
        if (StringUtils.isNotBlank(monitorPort)) {
            try {
                moitorPort = Integer.valueOf(monitorPort);
                if (moitorPort > 65535 || moitorPort < 1) {
                    showErrorMsg("端口号错误,只能输入1-66535");
                    return;
                }
            } catch (Exception ex) {
                showErrorMsg("端口号只能输入数字");
                return;
            }
        }

        if (debuggerPort != null && moitorPort != null && debuggerPort == moitorPort) {
            showErrorMsg("调试端口不能和监控端口一致");
            return;
        }

        try {
            new Save(sourceJarFile, saveConfigFile, saveSource.getAbsolutePath(), saveName1, startModeStr, desc, debuggerPort, moitorPort).build();
            JOptionPane.showMessageDialog(null, "保存成功", "提示", JOptionPane.INFORMATION_MESSAGE);
            java.awt.Desktop.getDesktop().open(new File(saveSource.getAbsolutePath() + "/" + saveName1));
        } catch (IOException ex) {
            showErrorMsg(ex.getLocalizedMessage());
        }
    }//GEN-LAST:event_saveBtnMouseClicked

    private void monitorPortCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_monitorPortCheckBoxItemStateChanged
        // TODO add your handling code here:
        // TODO add your handling code here:
        JCheckBox jcb = (JCheckBox) evt.getItem();
        monitorPortText.setEnabled(jcb.isSelected());
        monitorPortText.setText(null);
    }//GEN-LAST:event_monitorPortCheckBoxItemStateChanged

    private void monitorPortCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_monitorPortCheckBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_monitorPortCheckBoxActionPerformed

    private void saveNameTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveNameTitleActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_saveNameTitleActionPerformed

    private void serviceTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_serviceTitleActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_serviceTitleActionPerformed

    private void debugPortTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_debugPortTitleActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_debugPortTitleActionPerformed

    private void monitorPortTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_monitorPortTitleActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_monitorPortTitleActionPerformed

    private void saveNameTitleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveNameTitleMouseClicked
        // TODO add your handling code here:
        showRemindMsg("将会以该名称生成注册服务名称（即在服务中显示的名称）,同时保存的文件夹也会以该名称命名!");
    }//GEN-LAST:event_saveNameTitleMouseClicked

    private void serviceTitleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_serviceTitleMouseClicked
        // TODO add your handling code here:
        showRemindMsg("注册服务的说明信息,该信息将在注册服务后在服务的描述字段显示。");
    }//GEN-LAST:event_serviceTitleMouseClicked

    private void debugPortTitleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_debugPortTitleMouseClicked
        // TODO add your handling code here:
        showRemindMsg("可在idea中远程该端口远程DEBUG查找代码BUG,具体使用方法请百度 IDEA远程DEBUG");
    }//GEN-LAST:event_debugPortTitleMouseClicked

    private void monitorPortTitleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_monitorPortTitleMouseClicked
        // TODO add your handling code here:
        showRemindMsg("因服务运行时,无法在jvisualvm中找到该程序,通过新增JMX监控端口，可在jvisualvm中选择本地，右键-》添加JMX链接-》录入端口号，进行程序性能监控");
    }//GEN-LAST:event_monitorPortTitleMouseClicked

    private void startModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startModeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_startModeActionPerformed

    private void startModeTitleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_startModeTitleMouseClicked
        // TODO add your handling code here:
        showRemindMsg("注册服务启动模式");
    }//GEN-LAST:event_startModeTitleMouseClicked

    private void startModeTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startModeTitleActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_startModeTitleActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    String lookAndFeel = UIManager.getSystemLookAndFeelClassName();
                    UIManager.setLookAndFeel(lookAndFeel);
                    JFrame frame = new MainFrame();
                    frame.setVisible(true);
                    frame.setLocationRelativeTo(null);
                    frame.setResizable(false);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (UnsupportedLookAndFeelException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    private File sourceJarFile = null;
    private File saveSource = null;
    private File saveConfigFile = null;
    private String lastOpenFilePath = null;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton configFilePathBtn;
    private javax.swing.JTextField configFilePathText;
    private javax.swing.JCheckBox debugPortCheckBox;
    private javax.swing.JTextField debugPortText;
    private javax.swing.JButton debugPortTitle;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JComboBox<String> jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jarFilePathBtn;
    private javax.swing.JTextField jarFilePathText;
    private javax.swing.JCheckBox monitorPortCheckBox;
    private javax.swing.JTextField monitorPortText;
    private javax.swing.JButton monitorPortTitle;
    private javax.swing.JButton saveBtn;
    private javax.swing.JTextField saveNameText;
    private javax.swing.JButton saveNameTitle;
    private javax.swing.JButton savePathBtn;
    private javax.swing.JTextField savePathText;
    private javax.swing.JTextArea serviceDescriptionText;
    private javax.swing.JButton serviceTitle;
    private javax.swing.JComboBox<String> startMode;
    private javax.swing.JButton startModeTitle;
    // End of variables declaration//GEN-END:variables
private File selectFile(JButton button) {
        JFileChooser fileChooser;
        if (StringUtils.isBlank(lastOpenFilePath)) {
            fileChooser = new JFileChooser();
        } else {
            fileChooser = new JFileChooser(lastOpenFilePath);
        }

        int returnVal = fileChooser.showOpenDialog(button);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fileChooser.getSelectedFile().getAbsoluteFile();
            lastOpenFilePath = file.getAbsolutePath().substring(0, file.getAbsolutePath().lastIndexOf("\\"));
            return file;
        }
        return null;
    }

    private File selectDirectories(JButton button) {
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = fileChooser.showOpenDialog(button);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            return fileChooser.getSelectedFile().getAbsoluteFile();
        }
        return null;
    }

    private void showErrorMsg(String msg) {
        JOptionPane.showMessageDialog(null, msg, "错误提示", JOptionPane.ERROR_MESSAGE);
    }

    private void showRemindMsg(String msg) {
        JOptionPane.showMessageDialog(null, msg, "提示", JOptionPane.PLAIN_MESSAGE);
    }
}
